package mt.client;



import java.util.LinkedList;
import javax.swing.table.AbstractTableModel;
import mt.Order;


/**
 * 
 * Uma <code>ConfigTabelaHist</code> representa a table model para a JTable da Janela criada na classe GUI ( Sentinela User )
 * 
 * @author Grupo 41
 *
 *@see GUI
 */

public class ConfigTabelaHist extends AbstractTableModel {
	private LinkedList<Order> listaOrder = new LinkedList<Order>();
	

	@Override
	public int getColumnCount() {

		return 4;
	}

	@Override
	public String getColumnName(int column) {
		switch(column){
		case 0:
			return "User";
		case 1:
			return "Stock";
		case 2:
			return "Unit";
		case 3:
			return "Price";
		}
		return null;

	}

	@Override
	public int getRowCount() {

		return listaOrder.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {

		switch(columnIndex){
		case 0:
			return listaOrder.get(rowIndex).getNickname();
		case 1:
			return listaOrder.get(rowIndex).getStock();
		case 2:
			return listaOrder.get(rowIndex).getNumberOfUnits();
		case 3: 
			return listaOrder.get(rowIndex).getPricePerUnit();
		}

		return null;

	}
	
	
	/**
	 * Adicion na lista de order efectuada 
	 * @param order
	 *
	 */
	public void add(Order order){
		listaOrder.add(order);
		fireTableDataChanged();
	}

	/**
	 * Apaga uma Order e tambem remove da JTable
	 * @param order
	 * 
	 */
	public void delete(Order order){
		listaOrder.remove(order);
		fireTableDataChanged();
	}

	
	/**
	 * Devolve a Order pela posicao
	 * @param row
	 * @see Order
	 * @return a order pretendida se existir na lista
	 * 
	 */
	public Order getOrder(int row){
		return listaOrder.get(row);
	}
	
}
